package com.tequila.core.service.impl;

import com.google.common.collect.Lists;
import com.tequila.core.dao.AnaDao;
import com.tequila.core.service.AnaService;
import com.tequila.domain.dto.AnaDto;
import com.tequila.domain.entity.Ana;
import com.tequila.domain.query.AnaQuery;
import fe.core.Assert;
import fe.core.BeanHelper;
import fe.core.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AnaServiceImpl implements AnaService {
    public static final Logger logger = LoggerFactory.getLogger(AnaServiceImpl.class);

    @Resource
    private AnaDao anaDao;

    @Override
    public Pagination<AnaDto> queryPageListByParam(AnaQuery query) {
        Assert.assertNotNull(query);
        int total = anaDao.queryPageCountByParam(query);

        List<AnaDto> list = Lists.newArrayList();
        if (total > 0) {
            list = anaDao.queryPageListByParam(query);
        }
        return new Pagination<>(query, list, total);
    }

    @Override
    public AnaDto queryById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        Ana ana = anaDao.queryById(id);
        AnaDto anaDto = new AnaDto();
        BeanHelper.copyProperties(anaDto,ana);
        return anaDto;
    }

    @Override
    public List<AnaDto> queryByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return anaDao.queryByIdList(idList);
    }

    @Override
    public List<AnaDto> queryListByParam(AnaQuery query) {
        Assert.assertNotNull(query,"query不能为空!");
        return anaDao.queryListByParam(query);
    }


    @Override
    public Long insert(Ana entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        anaDao.insert(entity);
        return entity.getId();
    }

    @Override
    public Long save(Ana entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        anaDao.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public int updateById(Ana param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return anaDao.updateById(param);
    }

    @Override
    public int updateSelectiveById(Ana param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return anaDao.updateSelectiveById(param);
    }

    @Override
    public int deleteById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        return anaDao.deleteById(id);
    }

    @Override
    public int deleteByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return anaDao.deleteByIdList(idList);
    }
}
